package com.nomito.minimito.controller.front;

import com.nomito.minimito.common.utils.R;
import com.nomito.minimito.entity.ImUserEntity;
import com.nomito.minimito.service.ImFriendService;
import com.nomito.minimito.service.ImGroupfriendService;
import com.nomito.minimito.service.ImUserService;
import com.nomito.minimito.service.SqActivityService;
import com.nomito.minimito.vo.ActivityFootprintVo;
import com.nomito.minimito.vo.MyFriendsVO;
import com.nomito.minimito.vo.UserInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiaoxinwei
 * @date 2020/5/9
 */
@Api(tags = "我的主页信息")
@CrossOrigin
@RestController
@RequestMapping("/front")
public class FUseInfoController {
    @Autowired
    private ImUserService ImUserService;
    @Autowired
    private ImFriendService ImFriendService;
    @Autowired
    private ImGroupfriendService ImGroupfriendService;
    @Autowired
    private SqActivityService sqActivityService;

    /**
     * 查询个人头像、昵称和签名
     */
    @ApiOperation(value = "查询个人昵称、个性签名、头像、好友及群聊数量")
    @GetMapping("/userInfo")
    public R  userInfo(@RequestParam("userId")Long userId){
        //查询个人昵称、个性签名、头像
        UserInfoVo userInfoVo = ImUserService.queryUserInfo(userId);
        //查询好友数量
        long friendCount = ImFriendService.getFriendCount(userId);
        userInfoVo.setFridendsCount(friendCount);
        //查询群聊数量
        long groupCount = ImGroupfriendService.getGroupCount(userId);
        userInfoVo.setGroupCount(groupCount);
        if(userInfoVo != null){
            return R.ok().setData(userInfoVo);
        }else {
           return R.error("未知错误");
        }

    }

    /**
     * 修改用户个人信息
     */
    @ApiOperation(value = "修改个人信息")
    @PostMapping("/updateUserInfo")
    public R updateUserInfo(@RequestBody ImUserEntity userEntity){
        ImUserService.updateById(userEntity);
        return R.ok();
    }

    /**
     * 检索我参与的活动
     */
    @ApiOperation(value = "我参与的活动")
    @GetMapping("/joinedActivity")
    public R joinedActivity(@RequestParam("userId") Long userId){
        List<ActivityFootprintVo> activityFootprintVoList = sqActivityService.queryJoinedActivity(userId);
        return R.ok().put("data",activityFootprintVoList);
    }
}
